package com.hdoit.kylin.web.groupActivity.provider;

import java.util.ArrayList;
import java.util.List;

import com.hdoit.kylin.logical.user.model.Student;
import com.hdoit.kylin.logical.user.model.TeacherStudent;
import com.hdoit.kylin.logical.user.service.IStudentService;
import com.hdoit.kylin.logical.user.service.ITeacherStudentService;
import com.hdoit.kylin.logical.viewmodel.user.TeacherStudentSearch;
import com.hdoit.kylin.web.common.CommonWebUtils;
import com.hdoit.kylin.web.user.modelconfig.StudentConfig;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.common.message.LoginModel;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.component.web.SessionWebFactory;
import com.tennetcn.web.bootstrap.controllers.tables.DataTableController;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

public class GroupStudentProvider extends DataListProviderBase implements ISingleOptionListProvider<ListItem>{

	@Override
	public List<ListItem> getDataList(Object viewData) {
		dataList = new ArrayList<ListItem>();
		if(CommonWebUtils.isTeacher(getLoginModel())){
			ITeacherStudentService teacherStudentService = CommonApplicationContextUtil.getCurrentContext().getBean(ITeacherStudentService.class);
			TeacherStudentSearch search = new TeacherStudentSearch();
			search.setTeacherId(getLoginModel().getLoginId());
			List<TeacherStudent> students = teacherStudentService.queryList(search);
			IStudentService studentService = CommonApplicationContextUtil.getCurrentContext().getBean(IStudentService.class);
			for(TeacherStudent student:students){
				Student temp = studentService.queryModel(student.getStudentId());
				ListItem listItem = new ListItem();
				listItem.setText(temp.getStudentName());
				listItem.setValue(temp.getEmployeeId());
				dataList.add(listItem);
			}
		}
		else if(CommonWebUtils.isStudent(getLoginModel())){
			ListItem listItem = new ListItem();
			listItem.setText(getLoginModel().getLoginName());
			listItem.setValue(getLoginModel().getLoginId());
			dataList.add(listItem);
		}
		System.err.println(dataList.size());
		
		return dataList;
	}
	
	private LoginModel getLoginModel(){
		return CommonApplicationContextUtil.getCurrentContext().getBean(SessionWebFactory.class).getCurrentLogin();
	}

	
}
